#include "srvcfg_dlg.h"
#include "ui_srvcfg_dlg.h"

srvCfg_Dlg *srvCfg_Dlg::_ins = 0;
srvCfg_Dlg::srvCfg_Dlg(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::srvCfg_Dlg)
{
    ui->setupUi(this);
}

srvCfg_Dlg::~srvCfg_Dlg()
{
    delete ui;
}

void srvCfg_Dlg::on_srvCfg_OK_pBt_clicked()
{
    QSettings   *IniSettings;
    QStringList  keys;
    IniSettings =new QSettings(g_iniPath,QSettings::IniFormat);
    keys = IniSettings->allKeys();

    g_srvPara.cvrIP     =  ui->cvrIP_lEt->text();
    g_srvPara.cvrPort   =  ui->cvrPort_lEt->text().toInt();
    g_srvPara.cvrUser   =  ui->cvrUser_lEt->text();
    g_srvPara.cvrPwd    =  ui->cvrPWD_lEt->text();

    g_srvPara.platFormIP     =  ui->platFormIP_lEt->text();
    g_srvPara.platFormPort   =  ui->platFormPort_lEt->text().toInt();
    g_srvPara.platFormUser   =  ui->platFormUser_lEt->text();
    g_srvPara.platFormPwd    =  ui->platFormPWD_lEt->text();

    IniSettings->setValue("CVR/IP",g_srvPara.cvrIP );
    IniSettings->setValue("CVR/PORT",QString::number( g_srvPara.cvrPort));
    IniSettings->setValue("CVR/UserName",g_srvPara.cvrUser);
    IniSettings->setValue("CVR/PWD",g_srvPara.cvrPwd );
    IniSettings->setValue("CVR/HTTPS","disable");

    IniSettings->setValue("PLATFROM/IP",g_srvPara.cvrIP );
    IniSettings->setValue("PLATFROM/PORT",QString::number( g_srvPara.cvrPort));
    IniSettings->setValue("PLATFROM/UserName",g_srvPara.cvrUser);
    IniSettings->setValue("PLATFROM/PWD",g_srvPara.cvrPwd );
    IniSettings->sync();
    this->hide();
    g_rplyCenterDlg->show();
}

void srvCfg_Dlg::srvCfg_loadCfg(){

    ui->cvrIP_lEt->clear();
    ui->cvrIP_lEt->setText(g_srvPara.cvrIP);
    ui->cvrPort_lEt->clear();
    ui->cvrPort_lEt->setText(QString::number(g_srvPara.cvrPort));
    ui->cvrUser_lEt->clear();
    ui->cvrUser_lEt->setText(g_srvPara.cvrUser);
    ui->cvrPWD_lEt->clear();
    ui->cvrPWD_lEt->setText(g_srvPara.cvrPwd);


    ui->platFormIP_lEt->clear();
    ui->platFormIP_lEt->setText(g_srvPara.platFormIP);
    ui->platFormPort_lEt->clear();
    ui->platFormPort_lEt->setText(QString::number(g_srvPara.platFormPort));
    ui->platFormUser_lEt->clear();
    ui->platFormUser_lEt->setText(g_srvPara.platFormUser);
    ui->platFormPWD_lEt->clear();
    ui->platFormPWD_lEt->setText(g_srvPara.platFormPwd);

}
void srvCfg_Dlg::on_srvCfg_cancel_pBt_clicked()
{
    appExit();
}
